<?php
class DataGroupUsers{
	private $UsersInGroup = array();
	function __construct(){
	}
	static function swap($bytebuffer){
		$obj = new DataGroupUsers();
		$num_of_users = DataUtil::readInt32( $bytebuffer ) ;
		for($i = 0; $i < $num_of_users; $i++){
			$obj->UsersInGroup[] = DataUtil::readBBin( $bytebuffer ) ;
		}
		return $obj;
	}
	function addUser($username){
		if(is_array($this->UsersInGroup)){
			foreach($this->UsersInGroup as $user){
				if(implode(array_map("chr",  $user ))  == $username);
				return;
			}
		}
		$this->UsersInGroup[] = unpack('C*', $username ) ;
	}
	function getListUsers(){
		$rs = array();
		if(is_array($this->UsersInGroup)){
			foreach($this->UsersInGroup as $user){
				$rs[] = implode(array_map("chr",  $user )) ;
			}
		}
	}
	function getBinSize(){
		$size = 0;
		$size += 4 ;
		if(is_array($this->UsersInGroup)){
			foreach($this->UsersInGroup as $user){
				$size += 1  + count($user);
			}
		}
		return $size;
	}
	function getBinary(){
		$buf = ByteBuffer::allocate( $this->getBinSize() ) ;
		DataUtil::writeInt32( $buf , count($this->UsersInGroup) ) ;
		if(is_array($this->UsersInGroup)){
			foreach($this->UsersInGroup as $user){
				DataUtil::writeBBin( $buf , $user ) ;
			}
		}
		return  $buf ->_array() ;
	}
}
?>